﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;

using QLTTAN.DTO;
namespace QLTTAN.DAL
{
    public class TrinhDoDAL
    {
        ConnectionData conn;

        public DataTable TrinhDo_Load()
        {
            conn = new ConnectionData();
            return conn.GetData("TRINHDO_LOAD");
        }

        public DataRow TrinhDo_GetLastID()
        {
            conn = new ConnectionData();
            return conn.GetData("TRINHDO_LASTID").Rows[0];
        }

        public int TrinhDo_Insert(TrinhDoDTO TD_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "TenTrinhDo";
            value[0] = TD_DTO.TenTrinhDo;


            return conn.UpdateData("TRINHDO_INSERT", name, value, Nparameter);
        }

        public int TrinhDo_Update(TrinhDoDTO TD_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 2;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaTrinhDo";
            value[0] = TD_DTO.MaTrinhDo;
            name[1] = "TenTrinhDo";
            value[1] = TD_DTO.TenTrinhDo;


            return conn.UpdateData("TRINHDO_UPDATE", name, value, Nparameter);
        }

        public int TrinhDo_Delete(TrinhDoDTO TD_DTO)
        {
            conn = new ConnectionData();

            int Nparameter = 1;
            string[] name = new string[Nparameter];
            object[] value = new object[Nparameter];

            name[0] = "MaTrinhDo";
            value[0] = TD_DTO.MaTrinhDo;


            return conn.UpdateData("TRINHDO_DELETE", name, value, Nparameter);
        }
    }
}
